home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Help a fellow C programer
- Date: Sat, 13 Jan 96 14:11:20 GMT
- Organization: none
- Message-ID: <821542280snz@genesis.demon.co.uk>
- References: <4d3t4q$ea6@klein.delphi.com> <4d71td$88a@info.uah.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4d71td$88a@info.uah.edu> gbacon@oreo "Greg Bacon" writes:
-
- >int factorial(unsigned int a)
- >{
- > if ((a == 0) || (a == 1))
-
- For an unsigned type that is much the same as:
-
- if (a < 2)
-
- > return 1;
- > else
- > return a * factorial(a-1);
- >}
- >
- >That's a recursive version. a is unsigned since the factorial operation
- >is only defined over [0, \infinity)
-
- It makes sense to apply the same argument to the return value, e.g. making it
- unsigned long. Alternatively make it double or long double for a greater
- range.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-